package com.dmwork.service.interaction.mq.callback;

import com.dmwork.common.base.result.ExceptionUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Slf4j
@Data
@Component
public class ReturnCallback {

    private String callbackName;

    public static final String COMMENT_RETURN = "commentReturn";
    public static final String COMMENT_LIKE_RETURN = "commentLikeReturn";
    public static final String FEED_RETURN = "feedReturn";
    public static final String FEED_READ_RETURN = "feedReadReturn";
    public static final String COMMENT_READ_RETURN = "commentReadReturn";
    public static final String COMMENT_LIKE_READ_RETURN = "commentLikeReadReturn";
    public static final String BATCH_FILE_REMOVE_RETURN = "batchFileRemoveReturn";
    public static final String WORK_COLLECT_COUNT_CHANGE_RETURN="workCollectCountChangeReturn";



    public final RabbitTemplate.ReturnCallback originalReturnCallback = new RabbitTemplate.ReturnCallback() {
        @Override
        public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
            try {
                Method declaredMethod = ReturnCallback.class.getDeclaredMethod(callbackName, Message.class, int.class, String.class, String.class, String.class);
                declaredMethod.invoke(ReturnCallback.this, message, replyCode, replyText, exchange, routingKey);
            } catch (Exception e) {
                ExceptionUtils.getMessage(e);
            }
        }
    };

    public void commentReturn(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        log.info("-----------------comment returnCallback--------------------");
        log.info("replyCode: " + replyCode);
        log.info("replyText: " + replyText);
        log.info("exchange: " + exchange);
        log.info("routingKey: " + routingKey);
    }

    public void commentLikeReturn(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        log.info("-----------------commentLike returnCallback--------------------");
        log.info("replyCode: " + replyCode);
        log.info("replyText: " + replyText);
        log.info("exchange: " + exchange);
        log.info("routingKey: " + routingKey);
    }

    public void feedReturn(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        log.info("-----------------feed returnCallback--------------------");
        log.info("replyCode: " + replyCode);
        log.info("replyText: " + replyText);
        log.info("exchange: " + exchange);
        log.info("routingKey: " + routingKey);
    }

    public void feedReadReturn(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        log.info("-----------------feedRead returnCallback--------------------");
        log.info("replyCode: " + replyCode);
        log.info("replyText: " + replyText);
        log.info("exchange: " + exchange);
        log.info("routingKey: " + routingKey);
    }

    public void commentReadReturn(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        log.info("-----------------commentRead returnCallback--------------------");
        log.info("replyCode: " + replyCode);
        log.info("replyText: " + replyText);
        log.info("exchange: " + exchange);
        log.info("routingKey: " + routingKey);
    }

    public void commentLikeReadReturn(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        log.info("-----------------commentLikeRead returnCallback--------------------");
        log.info("replyCode: " + replyCode);
        log.info("replyText: " + replyText);
        log.info("exchange: " + exchange);
        log.info("routingKey: " + routingKey);
    }

    public void batchFileRemoveReturn(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        log.info("-----------------batchFileRemove returnCallback--------------------");
        log.info("replyCode: " + replyCode);
        log.info("replyText: " + replyText);
        log.info("exchange: " + exchange);
        log.info("routingKey: " + routingKey);
    }

    public void workCollectCountChangeReturn(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        log.info("-----------------workCollectCountChange returnCallback--------------------");
        log.info("replyCode: " + replyCode);
        log.info("replyText: " + replyText);
        log.info("exchange: " + exchange);
        log.info("routingKey: " + routingKey);
    }


}
